﻿using System.Collections.Generic;
using System.Linq;
using xraiding.Models;

namespace xraiding.ViewModels
{
    public class CharacterInfoViewModel
    {
        private XRaidingEntities _entities;

        public List<CharacterInfo> Characters { get; set; }

        public CharacterInfoViewModel()
        {
            Characters = new List<CharacterInfo>();
            _entities = XRaidingRepository.GetXRaidingConnection();
            Initialize();
        }

        private void Initialize()
        {
            var userId = XRaidingRepository.GetUserId();     
            var characters = (from c in _entities.Characters where c.UserId == userId select c).ToList();
            characters.ForEach(character => Characters.Add(new CharacterInfo
                                                               {
                                                                   CharacterId = character.CharacterId,
                                                                   Name = character.CharacterName,
                                                                   Realm = character.Realm,
                                                                   Class = character.Class.Name,
                                                                   PrimaryRole = character.PrimaryRole.Description,
                                                                   SecondaryRole = character.SecondaryRole.Description,
                                                                   Level = character.CharacterLevel.HasValue ? character.CharacterLevel.Value.ToString() : "N/A"
                                                               }));
        }
    }

    public class CharacterInfo
    {
        public int CharacterId { get; set; }
        public string Name { get; set; }
        public string Realm { get; set; }
        public string Class { get; set; }
        public string PrimaryRole { get; set; }
        public string SecondaryRole { get; set; }
        public string Level { get; set; }
    }
}